<?php

Class Database{
	
	private static $q;
	private static $res;

	
	private static $conexion;

	
	private function __construct(){
		$this->conexion=mysql_connect("localhost","root","");
		mysql_select_db("clinica", $this->conexion);
	}

	
	public static function conectar(){
		self::$conexion=mysql_connect("localhost","root","");
		mysql_select_db('clinica', self::$conexion);
	}
	
	
	public static function query($q){
		if (!self::$conexion) 	self::conectar();
		self::$res=mysql_query($q);
		
		while ($fila=mysql_fetch_assoc(self::$res)){
			$array[]= $fila;
		}
		//echo print_r($array);
		return $array;
		
	}

	public static function query_simple($q){
		if (!self::$conexion) 	self::conectar();
		self::$res=mysql_query($q);
		$fila=mysql_fetch_assoc(self::$res);
		return $fila;
		
	}
	
	
	public static function query_baja($q){
		if (!self::$conexion) 	self::conectar();
		self::$res=mysql_query($q);
	}

	
	public static function validar_digito($param){
		if(ctype_digit($param)){
			if(strlen($param) >= 1){
				if(strlen($param) > 15)
					$param = substr(0,15,$param);
				}
			else
				return NULL;
			$param = mysql_escape_string($param);
			return $param;
		}
		else
			return NULL;				
	}

	
	public static function validar_caracter($param){
		if(!ctype_digit($param)){
			if(strlen($param) >= 1){
				if(strlen($param) > 50)
					$param = substr(0,50,$param);
				}
			else
				return NULL;
			$param = mysql_escape_string($param);
			$param = strip_tags($param);
			$param = htmlentities($param);
			return $param;
		}
		else
			return NULL;				
	}	
}?>
